package com.engineering.elink.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.engineering.elink.co.CompanyDynamicCo;
import com.engineering.elink.common.Constant;
import com.engineering.elink.common.Pagination;
import com.engineering.elink.dao.CompanyDynamicMapper;
import com.engineering.elink.dao.UserMapper;
import com.engineering.elink.service.CompanyDynamicService;

@Service
public class CompanyDynamicServiceImpl implements CompanyDynamicService{

	@Autowired
	private CompanyDynamicMapper companyDynamicMapper;
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public Map<String, Object> getCompanyDynamicList(CompanyDynamicCo companyDynamicCo) {
		if (companyDynamicCo.getSearchType() == 1) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("list", companyDynamicMapper.selectCompanyDynamicList(companyDynamicCo));
			map.put("Pagination", new Pagination(companyDynamicCo, companyDynamicMapper.selectCompanyDynamicListCount(companyDynamicCo)));
			return map;
		}else {
			Map<String, Object> userMap = userMapper.selectByUserId(companyDynamicCo.getUserId());
			if (userMap != null && (int)userMap.get("userType") == Constant.companyUserType) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("list", companyDynamicMapper.selectCompanyDynamicList(companyDynamicCo));
				map.put("Pagination", new Pagination(companyDynamicCo, companyDynamicMapper.selectCompanyDynamicListCount(companyDynamicCo)));
				return map;
			}
		}
		return null;
	}
	
}
